﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Beckhoff
{
	/// <summary>
	/// 倍福的ADS协议，支持读取倍福的地址数据，关于端口号的选择，TwinCAT2，端口号801；TwinCAT3，端口号为851<br />
	/// Beckhoff ’s ADS protocol supports reading Beckhoff ’s address data. For the choice of port number, TwinCAT2, port number 801; TwinCAT3, port number 851
	/// </summary>
	/// <remarks>
	/// 支持的地址格式分三种，第一种是绝对的地址表示，比如M100，I100，Q100；第二种是字符串地址，采用s=aaaa;的表示方式；第三种是绝对内存地址采用i=1000000;的表示方式
	/// <br />
	/// <note type="important">
	/// 在实际的测试中，由于打开了VS软件对倍福PLC进行编程操作，会导致HslCommunicationDemo读取PLC发生间歇性读写失败的问题，此时需要关闭Visual Studio软件对倍福的
	/// 连接，之后HslCommunicationDemo就会读写成功，感谢QQ：1813782515 提供的解决思路。
	/// </note>
	/// </remarks>
	// Token: 0x020000B2 RID: 178
	public class BeckhoffAdsNet : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化一个默认的对象<br />
		/// Instantiate a default object
		/// </summary>
		// Token: 0x06000CE9 RID: 3305 RVA: 0x0004C760 File Offset: 0x0004A960
		public BeckhoffAdsNet()
		{
			base.WordLength = 2;
			this.targetAMSNetId[4] = 1;
			this.targetAMSNetId[5] = 1;
			this.targetAMSNetId[6] = 33;
			this.targetAMSNetId[7] = 3;
			this.sourceAMSNetId[4] = 1;
			this.sourceAMSNetId[5] = 1;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// 通过指定的ip地址以及端口号实例化一个默认的对象<br />
		/// Instantiate a default object with the specified IP address and port number
		/// </summary>
		/// <param name="ipAddress">IP地址信息</param>
		/// <param name="port">端口号</param>
		// Token: 0x06000CEA RID: 3306 RVA: 0x0004C814 File Offset: 0x0004AA14
		public BeckhoffAdsNet(string ipAddress, int port)
		{
			this.IpAddress = ipAddress;
			this.Port = port;
			base.WordLength = 2;
			this.targetAMSNetId[4] = 1;
			this.targetAMSNetId[5] = 1;
			this.targetAMSNetId[6] = 33;
			this.targetAMSNetId[7] = 3;
			this.sourceAMSNetId[4] = 1;
			this.sourceAMSNetId[5] = 1;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <inheritdoc />
		// Token: 0x06000CEB RID: 3307 RVA: 0x0004C8D8 File Offset: 0x0004AAD8
		protected override INetMessage GetNewNetMessage()
		{
			return new AdsNetMessage();
		}

		/// <inheritdoc />
		// Token: 0x170001F2 RID: 498
		// (get) Token: 0x06000CEC RID: 3308 RVA: 0x00027587 File Offset: 0x00025787
		// (set) Token: 0x06000CED RID: 3309 RVA: 0x0004C8E0 File Offset: 0x0004AAE0
		[HslMqttApi(HttpMethod = "GET", Description = "Get or set the IP address of the remote server. If it is a local test, then it needs to be set to 127.0.0.1")]
		public override string IpAddress
		{
			get
			{
				return base.IpAddress;
			}
			set
			{
				base.IpAddress = value;
				string[] array = base.IpAddress.Split(new char[]
				{
					'.'
				}, StringSplitOptions.RemoveEmptyEntries);
				for (int i = 0; i < array.Length; i++)
				{
					this.targetAMSNetId[i] = byte.Parse(array[i]);
				}
			}
		}

		/// <summary>
		/// 是否使用标签的名称缓存功能，默认为 <c>False</c><br />
		/// Whether to use tag name caching. The default is <c>False</c>
		/// </summary>
		// Token: 0x170001F3 RID: 499
		// (get) Token: 0x06000CEE RID: 3310 RVA: 0x0004C932 File Offset: 0x0004AB32
		// (set) Token: 0x06000CEF RID: 3311 RVA: 0x0004C93A File Offset: 0x0004AB3A
		public bool UseTagCache
		{
			get
			{
				return this.useTagCache;
			}
			set
			{
				this.useTagCache = value;
			}
		}

		/// <summary>
		/// 目标的地址，举例 192.168.0.1.1.1；也可以是带端口号 192.168.0.1.1.1:801<br />
		/// The address of the destination, for example 192.168.0.1.1.1; it can also be the port number 192.168.0.1.1.1: 801
		/// </summary>
		/// <remarks>
		/// Port：1: AMS Router; 2: AMS Debugger; 800: Ring 0 TC2 PLC; 801: TC2 PLC Runtime System 1; 811: TC2 PLC Runtime System 2; <br />
		/// 821: TC2 PLC Runtime System 3; 831: TC2 PLC Runtime System 4; 850: Ring 0 TC3 PLC; 851: TC3 PLC Runtime System 1<br />
		/// 852: TC3 PLC Runtime System 2; 853: TC3 PLC Runtime System 3; 854: TC3 PLC Runtime System 4; ...
		/// </remarks>
		/// <param name="amsNetId">AMSNet Id地址</param>
		// Token: 0x06000CF0 RID: 3312 RVA: 0x0004C944 File Offset: 0x0004AB44
		public void SetTargetAMSNetId(string amsNetId)
		{
			bool flag = !string.IsNullOrEmpty(amsNetId);
			if (flag)
			{
				BeckhoffAdsNet.StrToAMSNetId(amsNetId).CopyTo(this.targetAMSNetId, 0);
			}
		}

		/// <summary>
		/// 设置原目标地址 举例 192.168.0.100.1.1；也可以是带端口号 192.168.0.100.1.1:34567<br />
		/// Set the original destination address Example: 192.168.0.100.1.1; it can also be the port number 192.168.0.100.1.1: 34567
		/// </summary>
		/// <param name="amsNetId">原地址</param>
		// Token: 0x06000CF1 RID: 3313 RVA: 0x0004C974 File Offset: 0x0004AB74
		public void SetSenderAMSNetId(string amsNetId)
		{
			bool flag = !string.IsNullOrEmpty(amsNetId);
			if (flag)
			{
				BeckhoffAdsNet.StrToAMSNetId(amsNetId).CopyTo(this.sourceAMSNetId, 0);
				this.senderAMSNetId = amsNetId;
			}
		}

		/// <inheritdoc />
		// Token: 0x06000CF2 RID: 3314 RVA: 0x0004C9AC File Offset: 0x0004ABAC
		protected override OperateResult InitializationOnConnect(Socket socket)
		{
			bool flag = string.IsNullOrEmpty(this.senderAMSNetId);
			if (flag)
			{
				IPEndPoint ipendPoint = (IPEndPoint)socket.LocalEndPoint;
				this.sourceAMSNetId[6] = BitConverter.GetBytes(ipendPoint.Port)[0];
				this.sourceAMSNetId[7] = BitConverter.GetBytes(ipendPoint.Port)[1];
				ipendPoint.Address.GetAddressBytes().CopyTo(this.sourceAMSNetId, 0);
			}
			return base.InitializationOnConnect(socket);
		}

		/// <inheritdoc />
		// Token: 0x06000CF3 RID: 3315 RVA: 0x0004CA24 File Offset: 0x0004AC24
		[DebuggerStepThrough]
		protected override Task<OperateResult> InitializationOnConnectAsync(Socket socket)
		{
			BeckhoffAdsNet.<InitializationOnConnectAsync>d__15 <InitializationOnConnectAsync>d__ = new BeckhoffAdsNet.<InitializationOnConnectAsync>d__15();
			<InitializationOnConnectAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<InitializationOnConnectAsync>d__.<>4__this = this;
			<InitializationOnConnectAsync>d__.socket = socket;
			<InitializationOnConnectAsync>d__.<>1__state = -1;
			<InitializationOnConnectAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<InitializationOnConnectAsync>d__15>(ref <InitializationOnConnectAsync>d__);
			return <InitializationOnConnectAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 根据当前标签的地址获取到内存偏移地址<br />
		/// Get the memory offset address based on the address of the current label
		/// </summary>
		/// <param name="address">带标签的地址信息，例如s=A,那么标签就是A</param>
		/// <returns>内存偏移地址</returns>
		// Token: 0x06000CF4 RID: 3316 RVA: 0x0004CA70 File Offset: 0x0004AC70
		public OperateResult<uint> ReadValueHandle(string address)
		{
			bool flag = !address.StartsWith("s=");
			OperateResult<uint> result;
			if (flag)
			{
				result = new OperateResult<uint>(StringResources.Language.SAMAddressStartWrong);
			}
			else
			{
				OperateResult<byte[]> operateResult = this.BuildReadWriteCommand(address, 4, false, BeckhoffAdsNet.StrToAdsBytes(address.Substring(2)));
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<uint>(operateResult);
				}
				else
				{
					OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<uint>(operateResult2);
					}
					else
					{
						OperateResult operateResult3 = BeckhoffAdsNet.CheckResponse(operateResult2.Content);
						bool flag4 = !operateResult3.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<uint>(operateResult3);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<uint>(BitConverter.ToUInt32(operateResult2.Content, 46));
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 将字符串的地址转换为内存的地址，其他地址则不操作<br />
		/// Converts the address of a string to the address of a memory, other addresses do not operate
		/// </summary>
		/// <param name="address">地址信息，s=A的地址转换为i=100000的形式</param>
		/// <returns>地址</returns>
		// Token: 0x06000CF5 RID: 3317 RVA: 0x0004CB38 File Offset: 0x0004AD38
		public OperateResult<string> TransValueHandle(string address)
		{
			bool flag = address.StartsWith("s=");
			OperateResult<string> result;
			if (flag)
			{
				bool flag2 = this.useTagCache;
				if (flag2)
				{
					object obj = this.tagLock;
					lock (obj)
					{
						bool flag4 = this.tagCaches.ContainsKey(address);
						if (flag4)
						{
							return OperateResult.CreateSuccessResult<string>(string.Format("i={0}", this.tagCaches[address]));
						}
					}
				}
				OperateResult<uint> operateResult = this.ReadValueHandle(address);
				bool flag5 = !operateResult.IsSuccess;
				if (flag5)
				{
					result = OperateResult.CreateFailedResult<string>(operateResult);
				}
				else
				{
					bool flag6 = this.useTagCache;
					if (flag6)
					{
						object obj2 = this.tagLock;
						lock (obj2)
						{
							bool flag8 = !this.tagCaches.ContainsKey(address);
							if (flag8)
							{
								this.tagCaches.Add(address, operateResult.Content);
							}
						}
					}
					result = OperateResult.CreateSuccessResult<string>(string.Format("i={0}", operateResult.Content));
				}
			}
			else
			{
				result = OperateResult.CreateSuccessResult<string>(address);
			}
			return result;
		}

		/// <summary>
		/// 读取Ads设备的设备信息。主要是版本号，设备名称<br />
		/// Read the device information of the Ads device. Mainly version number, device name
		/// </summary>
		/// <returns>设备信息</returns>
		// Token: 0x06000CF6 RID: 3318 RVA: 0x0004CC8C File Offset: 0x0004AE8C
		[HslMqttApi("ReadAdsDeviceInfo", "读取Ads设备的设备信息。主要是版本号，设备名称")]
		public OperateResult<AdsDeviceInfo> ReadAdsDeviceInfo()
		{
			OperateResult<byte[]> operateResult = this.BuildReadDeviceInfoCommand();
			bool flag = !operateResult.IsSuccess;
			OperateResult<AdsDeviceInfo> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<AdsDeviceInfo>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<AdsDeviceInfo>(operateResult2);
				}
				else
				{
					OperateResult operateResult3 = BeckhoffAdsNet.CheckResponse(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<AdsDeviceInfo>(operateResult3);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<AdsDeviceInfo>(new AdsDeviceInfo(operateResult2.Content.RemoveBegin(42)));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 读取Ads设备的状态信息，其中<see cref="P:HslCommunication.OperateResult`2.Content1" />是Ads State，<see cref="P:HslCommunication.OperateResult`2.Content2" />是Device State<br />
		/// Read the status information of the Ads device, where <see cref="P:HslCommunication.OperateResult`2.Content1" /> is the Ads State, and <see cref="P:HslCommunication.OperateResult`2.Content2" /> is the Device State
		/// </summary>
		/// <returns>设备状态信息</returns>
		// Token: 0x06000CF7 RID: 3319 RVA: 0x0004CD20 File Offset: 0x0004AF20
		public OperateResult<ushort, ushort> ReadAdsState()
		{
			OperateResult<byte[]> operateResult = this.BuildReadStateCommand();
			bool flag = !operateResult.IsSuccess;
			OperateResult<ushort, ushort> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<ushort, ushort>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<ushort, ushort>(operateResult2);
				}
				else
				{
					OperateResult operateResult3 = BeckhoffAdsNet.CheckResponse(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<ushort, ushort>(operateResult3);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<ushort, ushort>(BitConverter.ToUInt16(operateResult2.Content, 42), BitConverter.ToUInt16(operateResult2.Content, 44));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 写入Ads的状态，可以携带数据信息，数据可以为空<br />
		/// Write the status of Ads, can carry data information, and the data can be empty
		/// </summary>
		/// <param name="state">ads state</param>
		/// <param name="deviceState">device state</param>
		/// <param name="data">数据信息</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000CF8 RID: 3320 RVA: 0x0004CDBC File Offset: 0x0004AFBC
		public OperateResult WriteAdsState(short state, short deviceState, byte[] data)
		{
			OperateResult<byte[]> operateResult = this.BuildWriteControlCommand(state, deviceState, data);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult operateResult3 = BeckhoffAdsNet.CheckResponse(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 释放当前的系统句柄，该句柄是通过<see cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReadValueHandle(System.String)" />获取的
		/// </summary>
		/// <param name="handle">句柄</param>
		/// <returns>是否释放成功</returns>
		// Token: 0x06000CF9 RID: 3321 RVA: 0x0004CE34 File Offset: 0x0004B034
		public OperateResult ReleaseSystemHandle(uint handle)
		{
			OperateResult<byte[]> operateResult = this.BuildReleaseSystemHandle(handle);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult operateResult3 = BeckhoffAdsNet.CheckResponse(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReadValueHandle(System.String)" />
		// Token: 0x06000CFA RID: 3322 RVA: 0x0004CEA8 File Offset: 0x0004B0A8
		[DebuggerStepThrough]
		public Task<OperateResult<uint>> ReadValueHandleAsync(string address)
		{
			BeckhoffAdsNet.<ReadValueHandleAsync>d__22 <ReadValueHandleAsync>d__ = new BeckhoffAdsNet.<ReadValueHandleAsync>d__22();
			<ReadValueHandleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<uint>>.Create();
			<ReadValueHandleAsync>d__.<>4__this = this;
			<ReadValueHandleAsync>d__.address = address;
			<ReadValueHandleAsync>d__.<>1__state = -1;
			<ReadValueHandleAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReadValueHandleAsync>d__22>(ref <ReadValueHandleAsync>d__);
			return <ReadValueHandleAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.TransValueHandle(System.String)" />
		// Token: 0x06000CFB RID: 3323 RVA: 0x0004CEF4 File Offset: 0x0004B0F4
		[DebuggerStepThrough]
		public Task<OperateResult<string>> TransValueHandleAsync(string address)
		{
			BeckhoffAdsNet.<TransValueHandleAsync>d__23 <TransValueHandleAsync>d__ = new BeckhoffAdsNet.<TransValueHandleAsync>d__23();
			<TransValueHandleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<TransValueHandleAsync>d__.<>4__this = this;
			<TransValueHandleAsync>d__.address = address;
			<TransValueHandleAsync>d__.<>1__state = -1;
			<TransValueHandleAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<TransValueHandleAsync>d__23>(ref <TransValueHandleAsync>d__);
			return <TransValueHandleAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReadAdsDeviceInfo" />
		// Token: 0x06000CFC RID: 3324 RVA: 0x0004CF40 File Offset: 0x0004B140
		[DebuggerStepThrough]
		public Task<OperateResult<AdsDeviceInfo>> ReadAdsDeviceInfoAsync()
		{
			BeckhoffAdsNet.<ReadAdsDeviceInfoAsync>d__24 <ReadAdsDeviceInfoAsync>d__ = new BeckhoffAdsNet.<ReadAdsDeviceInfoAsync>d__24();
			<ReadAdsDeviceInfoAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<AdsDeviceInfo>>.Create();
			<ReadAdsDeviceInfoAsync>d__.<>4__this = this;
			<ReadAdsDeviceInfoAsync>d__.<>1__state = -1;
			<ReadAdsDeviceInfoAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReadAdsDeviceInfoAsync>d__24>(ref <ReadAdsDeviceInfoAsync>d__);
			return <ReadAdsDeviceInfoAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReadAdsState" />
		// Token: 0x06000CFD RID: 3325 RVA: 0x0004CF84 File Offset: 0x0004B184
		[DebuggerStepThrough]
		public Task<OperateResult<ushort, ushort>> ReadAdsStateAsync()
		{
			BeckhoffAdsNet.<ReadAdsStateAsync>d__25 <ReadAdsStateAsync>d__ = new BeckhoffAdsNet.<ReadAdsStateAsync>d__25();
			<ReadAdsStateAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<ushort, ushort>>.Create();
			<ReadAdsStateAsync>d__.<>4__this = this;
			<ReadAdsStateAsync>d__.<>1__state = -1;
			<ReadAdsStateAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReadAdsStateAsync>d__25>(ref <ReadAdsStateAsync>d__);
			return <ReadAdsStateAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.WriteAdsState(System.Int16,System.Int16,System.Byte[])" />
		// Token: 0x06000CFE RID: 3326 RVA: 0x0004CFC8 File Offset: 0x0004B1C8
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAdsStateAsync(short state, short deviceState, byte[] data)
		{
			BeckhoffAdsNet.<WriteAdsStateAsync>d__26 <WriteAdsStateAsync>d__ = new BeckhoffAdsNet.<WriteAdsStateAsync>d__26();
			<WriteAdsStateAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAdsStateAsync>d__.<>4__this = this;
			<WriteAdsStateAsync>d__.state = state;
			<WriteAdsStateAsync>d__.deviceState = deviceState;
			<WriteAdsStateAsync>d__.data = data;
			<WriteAdsStateAsync>d__.<>1__state = -1;
			<WriteAdsStateAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<WriteAdsStateAsync>d__26>(ref <WriteAdsStateAsync>d__);
			return <WriteAdsStateAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReleaseSystemHandle(System.UInt32)" />
		// Token: 0x06000CFF RID: 3327 RVA: 0x0004D024 File Offset: 0x0004B224
		[DebuggerStepThrough]
		public Task<OperateResult> ReleaseSystemHandleAsync(uint handle)
		{
			BeckhoffAdsNet.<ReleaseSystemHandleAsync>d__27 <ReleaseSystemHandleAsync>d__ = new BeckhoffAdsNet.<ReleaseSystemHandleAsync>d__27();
			<ReleaseSystemHandleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<ReleaseSystemHandleAsync>d__.<>4__this = this;
			<ReleaseSystemHandleAsync>d__.handle = handle;
			<ReleaseSystemHandleAsync>d__.<>1__state = -1;
			<ReleaseSystemHandleAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReleaseSystemHandleAsync>d__27>(ref <ReleaseSystemHandleAsync>d__);
			return <ReleaseSystemHandleAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 读取PLC的数据，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A<br />
		/// Read PLC data, there are three formats of address, one: I, Q, M data information, such as M0, M100; two: memory address, i = 100000; three: tag address, s = A
		/// </summary>
		/// <param name="address">地址信息，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A</param>
		/// <param name="length">长度</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06000D00 RID: 3328 RVA: 0x0004D070 File Offset: 0x0004B270
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = this.TransValueHandle(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				address = operateResult.Content;
				OperateResult<byte[]> operateResult2 = this.BuildReadCommand(address, (int)length, false);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						OperateResult operateResult4 = BeckhoffAdsNet.CheckResponse(operateResult3.Content);
						bool flag4 = !operateResult4.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<byte[]>(operateResult4);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<byte[]>(SoftBasic.ArrayRemoveBegin<byte>(operateResult3.Content, 46));
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 写入PLC的数据，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A<br />
		/// There are three formats for the data written into the PLC. One: I, Q, M data information, such as M0, M100; two: memory address, i = 100000; three: tag address, s = A
		/// </summary>
		/// <param name="address">地址信息，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A</param>
		/// <param name="value">数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000D01 RID: 3329 RVA: 0x0004D128 File Offset: 0x0004B328
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = this.TransValueHandle(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				address = operateResult.Content;
				OperateResult<byte[]> operateResult2 = this.BuildWriteCommand(address, value, false);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						OperateResult operateResult4 = BeckhoffAdsNet.CheckResponse(operateResult3.Content);
						bool flag4 = !operateResult4.IsSuccess;
						if (flag4)
						{
							result = operateResult4;
						}
						else
						{
							result = OperateResult.CreateSuccessResult();
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 读取PLC的数据，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A<br />
		/// Read PLC data, there are three formats of address, one: I, Q, M data information, such as M0, M100; two: memory address, i = 100000; three: tag address, s = A
		/// </summary>
		/// <param name="address">PLC的地址信息，例如 M10</param>
		/// <param name="length">数据长度</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06000D02 RID: 3330 RVA: 0x0004D1C4 File Offset: 0x0004B3C4
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = this.TransValueHandle(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				address = operateResult.Content;
				OperateResult<byte[]> operateResult2 = this.BuildReadCommand(address, (int)length, true);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					else
					{
						OperateResult operateResult4 = BeckhoffAdsNet.CheckResponse(operateResult3.Content);
						bool flag4 = !operateResult4.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<bool[]>(operateResult4);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<bool[]>(SoftBasic.ByteToBoolArray(SoftBasic.ArrayRemoveBegin<byte>(operateResult3.Content, 46)));
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 写入PLC的数据，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A<br />
		/// There are three formats for the data written into the PLC. One: I, Q, M data information, such as M0, M100; two: memory address, i = 100000; three: tag address, s = A
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="value">数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000D03 RID: 3331 RVA: 0x0004D28C File Offset: 0x0004B48C
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] value)
		{
			OperateResult<string> operateResult = this.TransValueHandle(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				address = operateResult.Content;
				OperateResult<byte[]> operateResult2 = this.BuildWriteCommand(address, value, true);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						OperateResult operateResult4 = BeckhoffAdsNet.CheckResponse(operateResult3.Content);
						bool flag4 = !operateResult4.IsSuccess;
						if (flag4)
						{
							result = operateResult4;
						}
						else
						{
							result = OperateResult.CreateSuccessResult();
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 读取PLC的数据，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A<br />
		/// Read PLC data, there are three formats of address, one: I, Q, M data information, such as M0, M100; two: memory address, i = 100000; three: tag address, s = A
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06000D04 RID: 3332 RVA: 0x0001BA1E File Offset: 0x00019C1E
		[HslMqttApi("ReadByte", "")]
		public OperateResult<byte> ReadByte(string address)
		{
			return ByteTransformHelper.GetResultFromArray<byte>(this.Read(address, 1));
		}

		/// <summary>
		/// 写入PLC的数据，地址共有三种格式，一：I,Q,M数据信息，举例M0,M100；二：内存地址，i=100000；三：标签地址，s=A<br />
		/// There are three formats for the data written into the PLC. One: I, Q, M data information, such as M0, M100; two: memory address, i = 100000; three: tag address, s = A
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="value">数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000D05 RID: 3333 RVA: 0x0001BA2D File Offset: 0x00019C2D
		[HslMqttApi("WriteByte", "")]
		public OperateResult Write(string address, byte value)
		{
			return this.Write(address, new byte[]
			{
				value
			});
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.Read(System.String,System.UInt16)" />
		// Token: 0x06000D06 RID: 3334 RVA: 0x0004D328 File Offset: 0x0004B528
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			BeckhoffAdsNet.<ReadAsync>d__34 <ReadAsync>d__ = new BeckhoffAdsNet.<ReadAsync>d__34();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReadAsync>d__34>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.Write(System.String,System.Byte[])" />
		// Token: 0x06000D07 RID: 3335 RVA: 0x0004D37C File Offset: 0x0004B57C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			BeckhoffAdsNet.<WriteAsync>d__35 <WriteAsync>d__ = new BeckhoffAdsNet.<WriteAsync>d__35();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<WriteAsync>d__35>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000D08 RID: 3336 RVA: 0x0004D3D0 File Offset: 0x0004B5D0
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			BeckhoffAdsNet.<ReadBoolAsync>d__36 <ReadBoolAsync>d__ = new BeckhoffAdsNet.<ReadBoolAsync>d__36();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReadBoolAsync>d__36>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.Write(System.String,System.Boolean[])" />
		// Token: 0x06000D09 RID: 3337 RVA: 0x0004D424 File Offset: 0x0004B624
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] value)
		{
			BeckhoffAdsNet.<WriteAsync>d__37 <WriteAsync>d__ = new BeckhoffAdsNet.<WriteAsync>d__37();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<WriteAsync>d__37>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.ReadByte(System.String)" />
		// Token: 0x06000D0A RID: 3338 RVA: 0x0004D478 File Offset: 0x0004B678
		[DebuggerStepThrough]
		public Task<OperateResult<byte>> ReadByteAsync(string address)
		{
			BeckhoffAdsNet.<ReadByteAsync>d__38 <ReadByteAsync>d__ = new BeckhoffAdsNet.<ReadByteAsync>d__38();
			<ReadByteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte>>.Create();
			<ReadByteAsync>d__.<>4__this = this;
			<ReadByteAsync>d__.address = address;
			<ReadByteAsync>d__.<>1__state = -1;
			<ReadByteAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<ReadByteAsync>d__38>(ref <ReadByteAsync>d__);
			return <ReadByteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Beckhoff.BeckhoffAdsNet.Write(System.String,System.Byte)" />
		// Token: 0x06000D0B RID: 3339 RVA: 0x0004D4C4 File Offset: 0x0004B6C4
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, byte value)
		{
			BeckhoffAdsNet.<WriteAsync>d__39 <WriteAsync>d__ = new BeckhoffAdsNet.<WriteAsync>d__39();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<BeckhoffAdsNet.<WriteAsync>d__39>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 根据命令码ID，消息ID，数据信息组成AMS的命令码
		/// </summary>
		/// <param name="commandId">命令码ID</param>
		/// <param name="data">数据内容</param>
		/// <returns>打包之后的数据信息，没有填写AMSNetId的Target和Source内容</returns>
		// Token: 0x06000D0C RID: 3340 RVA: 0x0004D518 File Offset: 0x0004B718
		public byte[] BuildAmsHeaderCommand(ushort commandId, byte[] data)
		{
			bool flag = data == null;
			if (flag)
			{
				data = new byte[0];
			}
			uint value = (uint)this.incrementCount.GetCurrentValue();
			byte[] array = new byte[32 + data.Length];
			this.targetAMSNetId.CopyTo(array, 0);
			this.sourceAMSNetId.CopyTo(array, 8);
			array[16] = BitConverter.GetBytes(commandId)[0];
			array[17] = BitConverter.GetBytes(commandId)[1];
			array[18] = 4;
			array[19] = 0;
			array[20] = BitConverter.GetBytes(data.Length)[0];
			array[21] = BitConverter.GetBytes(data.Length)[1];
			array[22] = BitConverter.GetBytes(data.Length)[2];
			array[23] = BitConverter.GetBytes(data.Length)[3];
			array[24] = 0;
			array[25] = 0;
			array[26] = 0;
			array[27] = 0;
			array[28] = BitConverter.GetBytes(value)[0];
			array[29] = BitConverter.GetBytes(value)[1];
			array[30] = BitConverter.GetBytes(value)[2];
			array[31] = BitConverter.GetBytes(value)[3];
			data.CopyTo(array, 32);
			return BeckhoffAdsNet.PackAmsTcpHelper(array);
		}

		/// <summary>
		/// 构建读取设备信息的命令报文
		/// </summary>
		/// <returns>报文信息</returns>
		// Token: 0x06000D0D RID: 3341 RVA: 0x0004D620 File Offset: 0x0004B820
		public OperateResult<byte[]> BuildReadDeviceInfoCommand()
		{
			return OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(1, null));
		}

		/// <summary>
		/// 构建读取状态的命令报文
		/// </summary>
		/// <returns>报文信息</returns>
		// Token: 0x06000D0E RID: 3342 RVA: 0x0004D640 File Offset: 0x0004B840
		public OperateResult<byte[]> BuildReadStateCommand()
		{
			return OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(4, null));
		}

		/// <summary>
		/// 构建写入状态的命令报文
		/// </summary>
		/// <param name="state">Ads state</param>
		/// <param name="deviceState">Device state</param>
		/// <param name="data">Data</param>
		/// <returns>报文信息</returns>
		// Token: 0x06000D0F RID: 3343 RVA: 0x0004D660 File Offset: 0x0004B860
		public OperateResult<byte[]> BuildWriteControlCommand(short state, short deviceState, byte[] data)
		{
			bool flag = data == null;
			if (flag)
			{
				data = new byte[0];
			}
			byte[] array = new byte[8 + data.Length];
			return OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(5, SoftBasic.SpliceArray<byte>(new byte[][]
			{
				BitConverter.GetBytes(state),
				BitConverter.GetBytes(deviceState),
				BitConverter.GetBytes(data.Length),
				data
			})));
		}

		/// <summary>
		/// 构建写入的指令信息
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <param name="isBit">是否是位信息</param>
		/// <returns>结果内容</returns>
		// Token: 0x06000D10 RID: 3344 RVA: 0x0004D6C8 File Offset: 0x0004B8C8
		public OperateResult<byte[]> BuildReadCommand(string address, int length, bool isBit)
		{
			OperateResult<uint, uint> operateResult = BeckhoffAdsNet.AnalysisAddress(address, isBit);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] array = new byte[12];
				BitConverter.GetBytes(operateResult.Content1).CopyTo(array, 0);
				BitConverter.GetBytes(operateResult.Content2).CopyTo(array, 4);
				BitConverter.GetBytes(length).CopyTo(array, 8);
				result = OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(2, array));
			}
			return result;
		}

		/// <summary>
		/// 构建写入的指令信息
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <param name="isBit">是否是位信息</param>
		/// <param name="value">写入的数值</param>
		/// <returns>结果内容</returns>
		// Token: 0x06000D11 RID: 3345 RVA: 0x0004D744 File Offset: 0x0004B944
		public OperateResult<byte[]> BuildReadWriteCommand(string address, int length, bool isBit, byte[] value)
		{
			OperateResult<uint, uint> operateResult = BeckhoffAdsNet.AnalysisAddress(address, isBit);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] array = new byte[16 + value.Length];
				BitConverter.GetBytes(operateResult.Content1).CopyTo(array, 0);
				BitConverter.GetBytes(operateResult.Content2).CopyTo(array, 4);
				BitConverter.GetBytes(length).CopyTo(array, 8);
				BitConverter.GetBytes(value.Length).CopyTo(array, 12);
				value.CopyTo(array, 16);
				result = OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(9, array));
			}
			return result;
		}

		/// <summary>
		/// 构建写入的指令信息
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="value">数据</param>
		/// <param name="isBit">是否是位信息</param>
		/// <returns>结果内容</returns>
		// Token: 0x06000D12 RID: 3346 RVA: 0x0004D7E0 File Offset: 0x0004B9E0
		public OperateResult<byte[]> BuildWriteCommand(string address, byte[] value, bool isBit)
		{
			OperateResult<uint, uint> operateResult = BeckhoffAdsNet.AnalysisAddress(address, isBit);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] array = new byte[12 + value.Length];
				BitConverter.GetBytes(operateResult.Content1).CopyTo(array, 0);
				BitConverter.GetBytes(operateResult.Content2).CopyTo(array, 4);
				BitConverter.GetBytes(value.Length).CopyTo(array, 8);
				value.CopyTo(array, 12);
				result = OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(3, array));
			}
			return result;
		}

		/// <summary>
		/// 构建写入的指令信息
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="value">数据</param>
		/// <param name="isBit">是否是位信息</param>
		/// <returns>结果内容</returns>
		// Token: 0x06000D13 RID: 3347 RVA: 0x0004D86C File Offset: 0x0004BA6C
		public OperateResult<byte[]> BuildWriteCommand(string address, bool[] value, bool isBit)
		{
			OperateResult<uint, uint> operateResult = BeckhoffAdsNet.AnalysisAddress(address, isBit);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] array = SoftBasic.BoolArrayToByte(value);
				byte[] array2 = new byte[12 + array.Length];
				BitConverter.GetBytes(operateResult.Content1).CopyTo(array2, 0);
				BitConverter.GetBytes(operateResult.Content2).CopyTo(array2, 4);
				BitConverter.GetBytes(array.Length).CopyTo(array2, 8);
				array.CopyTo(array2, 12);
				result = OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(3, array2));
			}
			return result;
		}

		/// <summary>
		/// 构建释放句柄的报文信息，当获取了变量的句柄后，这个句柄就被释放
		/// </summary>
		/// <param name="handle">句柄信息</param>
		/// <returns>报文的结果内容</returns>
		// Token: 0x06000D14 RID: 3348 RVA: 0x0004D900 File Offset: 0x0004BB00
		public OperateResult<byte[]> BuildReleaseSystemHandle(uint handle)
		{
			byte[] array = new byte[16];
			BitConverter.GetBytes(61446).CopyTo(array, 0);
			BitConverter.GetBytes(4).CopyTo(array, 8);
			BitConverter.GetBytes(handle).CopyTo(array, 12);
			return OperateResult.CreateSuccessResult<byte[]>(this.BuildAmsHeaderCommand(3, array));
		}

		/// <inheritdoc />
		// Token: 0x06000D15 RID: 3349 RVA: 0x0004D956 File Offset: 0x0004BB56
		public override string ToString()
		{
			return string.Format("BeckhoffAdsNet[{0}:{1}]", this.IpAddress, this.Port);
		}

		/// <summary>
		/// 检查从PLC的反馈的数据报文是否正确
		/// </summary>
		/// <param name="response">反馈报文</param>
		/// <returns>检查结果</returns>
		// Token: 0x06000D16 RID: 3350 RVA: 0x0004D974 File Offset: 0x0004BB74
		public static OperateResult CheckResponse(byte[] response)
		{
			try
			{
				int num = BitConverter.ToInt32(response, 38);
				bool flag = num != 0;
				if (flag)
				{
					return new OperateResult(num, StringResources.Language.UnknownError + " Source:" + response.ToHexString(' '));
				}
			}
			catch (Exception ex)
			{
				return new OperateResult(ex.Message + " Source:" + response.ToHexString(' '));
			}
			return OperateResult.CreateSuccessResult();
		}

		/// <summary>
		/// 将实际的包含AMS头报文和数据报文的命令，打包成实际可发送的命令
		/// </summary>
		/// <param name="command">命令信息</param>
		/// <returns>结果信息</returns>
		// Token: 0x06000D17 RID: 3351 RVA: 0x0004D9F8 File Offset: 0x0004BBF8
		public static byte[] PackAmsTcpHelper(byte[] command)
		{
			byte[] array = new byte[6 + command.Length];
			BitConverter.GetBytes(command.Length).CopyTo(array, 2);
			command.CopyTo(array, 6);
			return array;
		}

		/// <summary>
		/// 分析当前的地址信息，根据结果信息进行解析出真实的偏移地址
		/// </summary>
		/// <param name="address">地址</param>
		/// <param name="isBit">是否位访问</param>
		/// <returns>结果内容</returns>
		// Token: 0x06000D18 RID: 3352 RVA: 0x0004DA30 File Offset: 0x0004BC30
		public static OperateResult<uint, uint> AnalysisAddress(string address, bool isBit)
		{
			OperateResult<uint, uint> operateResult = new OperateResult<uint, uint>();
			try
			{
				bool flag = address.StartsWith("i=");
				if (flag)
				{
					operateResult.Content1 = 61445U;
					operateResult.Content2 = uint.Parse(address.Substring(2));
				}
				else
				{
					bool flag2 = address.StartsWith("s=");
					if (flag2)
					{
						operateResult.Content1 = 61443U;
						operateResult.Content2 = 0U;
					}
					else
					{
						char c = address[0];
						char c2 = c;
						if (c2 <= 'Q')
						{
							if (c2 == 'I')
							{
								goto IL_CA;
							}
							if (c2 != 'M')
							{
								if (c2 != 'Q')
								{
									goto IL_112;
								}
								goto IL_EE;
							}
						}
						else
						{
							if (c2 == 'i')
							{
								goto IL_CA;
							}
							if (c2 != 'm')
							{
								if (c2 != 'q')
								{
									goto IL_112;
								}
								goto IL_EE;
							}
						}
						if (isBit)
						{
							operateResult.Content1 = 16417U;
						}
						else
						{
							operateResult.Content1 = 16416U;
						}
						goto IL_122;
						IL_CA:
						if (isBit)
						{
							operateResult.Content1 = 61473U;
						}
						else
						{
							operateResult.Content1 = 61472U;
						}
						goto IL_122;
						IL_EE:
						if (isBit)
						{
							operateResult.Content1 = 61489U;
						}
						else
						{
							operateResult.Content1 = 61488U;
						}
						goto IL_122;
						IL_112:
						throw new Exception(StringResources.Language.NotSupportedDataType);
						IL_122:
						operateResult.Content2 = uint.Parse(address.Substring(1));
					}
				}
			}
			catch (Exception ex)
			{
				operateResult.Message = ex.Message;
				return operateResult;
			}
			operateResult.IsSuccess = true;
			operateResult.Message = StringResources.Language.SuccessText;
			return operateResult;
		}

		/// <summary>
		/// 将字符串名称转变为ADS协议可识别的字节数组
		/// </summary>
		/// <param name="value">值</param>
		/// <returns>字节数组</returns>
		// Token: 0x06000D19 RID: 3353 RVA: 0x0004DBC8 File Offset: 0x0004BDC8
		public static byte[] StrToAdsBytes(string value)
		{
			return SoftBasic.SpliceArray<byte>(new byte[][]
			{
				Encoding.ASCII.GetBytes(value),
				new byte[1]
			});
		}

		/// <summary>
		/// 将字符串的信息转换为AMS目标的地址
		/// </summary>
		/// <param name="amsNetId">目标信息</param>
		/// <returns>字节数组</returns>
		// Token: 0x06000D1A RID: 3354 RVA: 0x0004DBFC File Offset: 0x0004BDFC
		public static byte[] StrToAMSNetId(string amsNetId)
		{
			string text = amsNetId;
			bool flag = amsNetId.IndexOf(':') > 0;
			byte[] array;
			if (flag)
			{
				array = new byte[8];
				string[] array2 = amsNetId.Split(new char[]
				{
					':'
				}, StringSplitOptions.RemoveEmptyEntries);
				text = array2[0];
				array[6] = BitConverter.GetBytes(int.Parse(array2[1]))[0];
				array[7] = BitConverter.GetBytes(int.Parse(array2[1]))[1];
			}
			else
			{
				array = new byte[6];
			}
			string[] array3 = text.Split(new char[]
			{
				'.'
			}, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array3.Length; i++)
			{
				array[i] = byte.Parse(array3[i]);
			}
			return array;
		}

		// Token: 0x04000371 RID: 881
		private byte[] targetAMSNetId = new byte[8];

		// Token: 0x04000372 RID: 882
		private byte[] sourceAMSNetId = new byte[8];

		// Token: 0x04000373 RID: 883
		private string senderAMSNetId = string.Empty;

		// Token: 0x04000374 RID: 884
		private bool useTagCache = false;

		// Token: 0x04000375 RID: 885
		private readonly Dictionary<string, uint> tagCaches = new Dictionary<string, uint>();

		// Token: 0x04000376 RID: 886
		private readonly object tagLock = new object();

		// Token: 0x04000377 RID: 887
		private readonly SoftIncrementCount incrementCount = new SoftIncrementCount(2147483647L, 1L, 1);
	}
}
